package com.rh.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rh.dto.Page;
import com.rh.entity.Department;
import com.rh.mapper.DepartmentMapper;
import com.rh.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public void addMethod(Department department) {
        departmentMapper.addMethod(department);
    }

    @Override
    public void deleteMethod(Integer deptId) {
    departmentMapper.deleteMethod(deptId);
    }

    @Override
    public void updateMethod(Department department) {
        departmentMapper.updateMethod(department);
    }

    @Override
    public Page getDepartmentPage(Integer pageNo, Integer pageSize) {
       Page page=new Page();
        PageHelper.startPage(pageNo,pageSize);
        List<Department> methodAll = departmentMapper.getMethodAll();
        PageInfo<Department>info=new PageInfo<>(methodAll);
        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setPageCount(info.getPages());
        page.setHasPre(info.isHasPreviousPage());
        page.setHasNext(info.isHasNextPage());
        page.setCount(info.getTotal());
        page.setPage(info.getList());
        return page;
    }

    @Override
    public Department getMethodAllById(Integer deptId) {
        return departmentMapper.getMethodAllById(deptId);
    }
}
